package com.job.admin.message.controller;

import com.alibaba.fastjson2.JSON;
import com.job.admin.message.pojo.Base64Data;
import com.job.admin.message.service.MessageService;
import com.job.client.common.result.ResponseResult;
import com.job.admin.message.pojo.MessageItem;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/v1/admin/message")
public class MessageController {
    @Autowired
    private MessageService messageService;
    @PostMapping("/init")
    @ApiOperation("初始化，之前没有记录就创建一个新的")
    public ResponseResult createMessage(@RequestParam String messageId){
        return messageService.createMessage(messageId);
    }
    @PostMapping("/createConnect")
    @ApiOperation("创建会话，创建和某用户的单独对话,messageId表示记录的id")
    public ResponseResult createConnect(@RequestParam String messageId,
                                        @RequestParam String connectId,
                                        @RequestBody MessageItem messageItem){
        return messageService.createConnect(messageId,connectId,messageItem);
    }
    @PostMapping("/saveMessage")
    @ApiOperation("保存聊天记录")
    public ResponseResult saveMessage(@RequestParam String messageId,
                                      @RequestParam String connectId,
                                      @RequestBody MessageItem messageItem){
        return messageService.saveMessage(messageId,connectId,messageItem);
    }
    @GetMapping("/getById")
    @ApiOperation("根据用户id获得聊天记录")
    public ResponseResult getById(@RequestParam String userId){
        return messageService.getById(userId);
    }
    @DeleteMapping("/deleteById")
    @ApiOperation("根据用户id删除数据")
    public ResponseResult deleteById(@RequestParam String userId){
        return messageService.deleteById(userId);
    }
    @PostMapping("/uploadImgMessage")
    @ApiOperation("上传用户聊天图片到minio中")
    public ResponseResult uploadAvatar(@RequestParam MultipartFile file, HttpServletRequest request){
        return messageService.uploadAvatar(file,request);
    }
    @GetMapping("/getUserId")
    @ApiOperation("获得客户端用户信息")
    public ResponseResult getUserInfo(@RequestParam String userId){
        return messageService.getUserInfo(userId);
    }
    @GetMapping("/getAuditInfo")
    @ApiOperation("获得当前用户未审核的数据")
    public ResponseResult getAuditInfo(@RequestParam String userId){
        return messageService.getAuditInfo(userId);
    }
    @GetMapping("/clearNumber")
    @ApiOperation("清除用户未读的数量")
    public ResponseResult clearNumber(@RequestParam String userId){
        return messageService.clearNumber(userId);
    }
    @PostMapping("/sendMessage")
    @ApiOperation("发送消息给用户")
    public ResponseResult sendMessage(@RequestParam String userId,@RequestBody MessageItem messageItem){
        return messageService.sendMessage(userId,messageItem);
    }
    @PostMapping("/sendScreenshot")
    @ApiOperation("接收前端截图的base64数据")
    public ResponseResult sendScreenshot(@RequestBody Base64Data data){
        return messageService.sendScreenshot(data.getBase64());
    }
}
